package by.jabbby.dataprovider;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class AccountProvider {
	private Context context;
	public AccountProvider(Context context){
		this.context = context;
	}
	public Map<String, Account> getAllUser(){
		Map<String, Account> accaunts = new HashMap<String, Account>();
		Account test = getTestAccount();
		accaunts.put(test.getConnectionString(),test );
		return accaunts ;
	}
	
	public Account getTestAccount(){
		
		JabberServer js = new JabberServer("jabber.ru");
		Account account = new Account(js);
		account.setLogin("jabbby");
		account.setPassword("daisyw");
		
		//account.setDomen("jabber.ru");
		
		
		return account;
	}
	
	public Account getCurrentAccount() throws Exception{
		
		
		
		SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(context);
		//by.jabbby.ui.act.R.string.st_acc_account.
		String st_acc_account = preferences.getString("st_acc_account", null);
		String st_acc_jb_id = preferences.getString("st_acc_jb_id", null);
		String st_acc_jb_service = preferences.getString("st_acc_jb_service", null);
		String st_acc_pasword = preferences.getString("st_acc_pasword", null);
		String st_acc_server_port = preferences.getString("st_acc_server_port", "5222");
	//	String _account = preferences.getString("st_acc_account", null);
	// _account = preferences.getString("st_acc_account", null);
		JabberServer js = new JabberServer(st_acc_jb_service);
		js.setPort(Integer.valueOf(st_acc_server_port));
		Account account  = new Account(js);
		account.setLogin(st_acc_jb_id);
		account.setPassword(st_acc_pasword);
	//	throw new Exception("test exc");
		return account;
	}

}

